<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>throttle</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            padding: 10px;
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <div id="dev1" draggable="true">
        拖拽
    </div>
    <script>

        function throttle(fn, delay = 200) {
            let timer = 0
            return function () {
                if (timer) return
                timer = setTimeout(() => {
                    fn.apply(this, arguments);
                    timer = 0;
                }, 300)
            }
        }
        
        const dev1 = document.getElementById("dev1")
        dev1.addEventListener("drag", throttle((e) => {
            console.log('拖拽位置', e.offsetX, e.offsetY);
        }))
    </script>
</body>

</html>